package me.aartikov.navigationmethodssample;

import me.aartikov.alligator.*;
import me.aartikov.alligator.navigationfactories.GeneratedNavigationFactory;
import me.aartikov.alligator.navigationfactories.NavigationFactory;
import me.aartikov.alligator.util.Log;
import ohos.aafwk.ability.AbilityPackage;
import ohos.app.ElementsCallback;
import ohos.global.configuration.Configuration;

public class SampleApplication extends AbilityPackage {
    private static OhosNavigator sOhosNavigator;
    private static long lastCLickTime;

    public static void setLastCLickTime(long lastCLickTime) {
        SampleApplication.lastCLickTime = lastCLickTime;
    }

    public static void setsOhosNavigator(OhosNavigator sOhosNavigator) {
        SampleApplication.sOhosNavigator = sOhosNavigator;
    }

    private static SampleApplication instance;

    public static void setInstance(SampleApplication instance) {
        SampleApplication.instance = instance;
    }

    public static SampleApplication getInstance() {
        return instance;
    }

    public boolean doubleClick() {
        boolean isSingleClick = System.currentTimeMillis() - lastCLickTime < 500;
        if (!isSingleClick) {
            setLastCLickTime(System.currentTimeMillis());
        }
        return isSingleClick;
    }


    @Override
    public void onInitialize() {
        super.onInitialize();
        setInstance(this);
        Log.i("MyApplication.onInitialize([]):24");
        setsOhosNavigator(new OhosNavigator(new GeneratedNavigationFactory()));
        registerCallbacks(AbilityStack.getInstance(), new ElementsCallback() {
            @Override
            public void onMemoryLevel(int i) {
                Log.i("MyApplication.onMemoryLevel([i]):29    " + i);
            }

            @Override
            public void onConfigurationUpdated(Configuration configuration) {

            }
        });
    }


    public static Navigator getNavigator() {
        return sOhosNavigator;
    }

    public static NavigationFactory getNavigationFactory() {
        return sOhosNavigator.getNavigationFactory();
    }

    public static NavigationContextBinder getNavigationContextBinder() {
        return sOhosNavigator;
    }

    public static ScreenResolver getScreenResolver() {
        return sOhosNavigator.getScreenResolver();
    }
}
